namespace Maple.Branch.Features.Extensions
{
    using System;
    using System.Collections.Generic;
    using System.Threading.Tasks;
    using IServices;
    using JetBrains.Annotations;
    using Models;
    using Volo.Abp.Features;

    public static class FeatureManagerExtensions
    {
        #region Default Value

        public static Task<string> GetOrNullDefaultAsync(this IBranchFeatureManager featureManager, [NotNull] string name, bool fallback = true)
        {
            return featureManager.GetOrNullAsync(name, DefaultValueFeatureValueProvider.ProviderName, null, fallback);
        }

        public static Task<List<FeatureNameValue>> GetAllDefaultAsync(this IBranchFeatureManager featureManager, bool fallback = true)
        {
            return featureManager.GetAllAsync(DefaultValueFeatureValueProvider.ProviderName, null, fallback);
        }

        #endregion

        #region Edition

        public static Task<string> GetOrNullForEditionAsync(this IBranchFeatureManager featureManager, [NotNull] string name, Guid editionId, bool fallback = true)
        {
            return featureManager.GetOrNullAsync(name, EditionFeatureValueProvider.ProviderName, editionId.ToString(), fallback);
        }

        public static Task<List<FeatureNameValue>> GetAllForEditionAsync(this IBranchFeatureManager featureManager, Guid editionId, bool fallback = true)
        {
            return featureManager.GetAllAsync(EditionFeatureValueProvider.ProviderName, editionId.ToString(), fallback);
        }

        public static Task SetForEditionAsync(this IBranchFeatureManager featureManager, Guid editionId, [NotNull] string name, [CanBeNull] string value, bool forceToSet = false)
        {
            return featureManager.SetAsync(name, value, EditionFeatureValueProvider.ProviderName, editionId.ToString(), forceToSet);
        }

        #endregion

        #region Tenant

        public static Task<string> GetOrNullForTenantAsync(this IBranchFeatureManager featureManager, [NotNull] string name, Guid tenantId, bool fallback = true)
        {
            return featureManager.GetOrNullAsync(name, TenantFeatureValueProvider.ProviderName, tenantId.ToString(), fallback);
        }

        public static Task<List<FeatureNameValue>> GetAllForTenantAsync(this IBranchFeatureManager featureManager, Guid tenantId, bool fallback = true)
        {
            return featureManager.GetAllAsync(TenantFeatureValueProvider.ProviderName, tenantId.ToString(), fallback);
        }

        public static Task SetForTenantAsync(this IBranchFeatureManager featureManager, Guid tenantId, [NotNull] string name, [CanBeNull] string value, bool forceToSet = false)
        {
            return featureManager.SetAsync(name, value, TenantFeatureValueProvider.ProviderName, tenantId.ToString(), forceToSet);
        }

        #endregion
    }
}
